﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSoftSeo.Models;

namespace WebSoftSeo.Areas.Admin.Controllers
{
    public class ServiceController : Controller
    {
        private WebSoftSeoEntities db = new WebSoftSeoEntities();

        //
        // GET: /Admin/Service/

        public ActionResult Index()
        {
            var service1 = db.ServicesDetails.Where(m => m.Type == "1").ToList();
            var service2 = db.ServicesDetails.Where(m => m.Type == "2").ToList();
            var service3 = db.ServicesDetails.Where(m => m.Type == "3").ToList();
            ViewBag.service1 = service1;
            ViewBag.service3 = service3;
            return View(service2);
        }

        //
        // GET: /Admin/Service/Details/5

        public ActionResult Details(int id = 0)
        {
            ServicesDetail servicesdetail = db.ServicesDetails.Find(id);
            if (servicesdetail == null)
            {
                return HttpNotFound();
            }
            return View(servicesdetail);
        }

        //
        // GET: /Admin/Service/Create

        public ActionResult Create(string type)
        {
            ViewBag.type = type;
            return View();
        }

        //
        // POST: /Admin/Service/Create

        [HttpPost, ValidateInput(false)]
        public ActionResult Create(ServicesDetail servicesdetail, string type)
        {
            servicesdetail.Type = type;
            if (ModelState.IsValid)
            {
                db.ServicesDetails.Add(servicesdetail);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(servicesdetail);
        }

        //
        // GET: /Admin/Service/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ServicesDetail servicesdetail = db.ServicesDetails.Find(id);
            if (servicesdetail == null)
            {
                return HttpNotFound();
            }
            return View(servicesdetail);
        }

        //
        // POST: /Admin/Service/Edit/5

        [HttpPost, ValidateInput(false)]
        public ActionResult Edit(ServicesDetail servicesdetail, int type)
        {
            if (ModelState.IsValid)
            {
                db.Entry(servicesdetail).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(servicesdetail);
        }

        //
        // GET: /Admin/Service/Delete/5

        public ActionResult Delete(int id = 0)
        {
            ServicesDetail servicesdetail = db.ServicesDetails.Find(id);
            if (servicesdetail == null)
            {
                return HttpNotFound();
            }
            return View(servicesdetail);
        }

        //
        // POST: /Admin/Service/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            ServicesDetail servicesdetail = db.ServicesDetails.Find(id);
            db.ServicesDetails.Remove(servicesdetail);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}